using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;
using ECommerce.Library.Web;

public partial class admin_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;
    }
    protected void imbLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string emailAddress = tbxEmailAddress.Text;
            string password = tbxPassword.Text;
            if (AutoGearSiteUser.Login(emailAddress, password, UserLocationType.BackEnd ))
            {
                if (cbxRemember.Checked)
                {
                    CookieManager.SetCookieValue(CookieManager.USER_NAME, emailAddress, DateTime.Now.AddDays(SiteSettings.CookieTimeOut));
                    CookieManager.SetCookieValue(CookieManager.PASSWORD, password, DateTime.Now.AddDays(SiteSettings.CookieTimeOut));
                }
                else
                {
                    CookieManager.RemoveCookie(CookieManager.USER_NAME);
                    CookieManager.RemoveCookie(CookieManager.PASSWORD);
                }

                if (SessionManager.ReturnUrl != null)
                {
                    string returnUrl = SessionManager.ReturnUrl;
                    SessionManager.ReturnUrl = null;
                    Response.Redirect(returnUrl);
                }
                else
                {
                    Response.Redirect(AutoGear.BLL.CustomSiteMap.AdminHome);
                }
            }
            else
            {
                uccResponseMessage.SetFailMessage("Login failed. Please try again");
                uccResponseMessage.Visible = true;
            }
        }
        catch (Exception ex)
        {
            uccResponseMessage.SetFailMessage("Login failed. Please try again");
            uccResponseMessage.Visible = true;
        }
    }
}
